package com.itfenghuang.day11;

public class 多线程复习 {
    public static void main(String[] args) {
        //java中的多线程是一种抢占式调度
        Aaa a = new Aaa();
        a.start();
        //获取当前执行线程的名称
        Thread thread = Thread.currentThread();
        System.out.println(thread.getName());
        //设置名称
        thread.setName("当前执行的线程名称");
        System.out.println(thread.getName());
        //获取线程优先级
        System.out.println(thread.getPriority());
        //设置优先级
        thread.setPriority(1);
        System.out.println(thread.getPriority());

        Thread thread2 = new Thread(new Runnable1());
        thread2.start();




    }
}
class Aaa extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);//设置线程休眠时间  1s=1000hm
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("看看"+i);
        }
        System.out.println(Thread.currentThread().getName());// 在不同地方调用这个方法,获取到的线程对象有什么不同
    }
}
class Runnable1 implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);//设置线程休眠时间  1s=1000hm
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("uuuuuuuuuuuuuu"+i);
        }
        System.out.println(Thread.currentThread().getName());
    }
}